//  RemindPaySecretAlert.m
//  XJMTechnician
//  Created by Mr.hu on 2017/10/26.
//  Copyright © 2017年 Mr.hu. All rights reserved.

#import "RemindPaySecretAlert.h"

@interface RemindPaySecretAlert ()
{
    CGFloat addCode;
}
/** 注释 **/
@property (copy, nonatomic) NSString * codeStr;

@end

@implementation RemindPaySecretAlert

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        
        
        CGFloat tenfloat = 10;
        CGFloat widthcancelbind = ScreenWidth-80;
        CGFloat heightcancelbind = (ScreenWidth-80)*4/5+80;
        
        UIView * subview = [[UIView alloc]initWithFrame:CGRectMake(40, (ScreenHeight - heightcancelbind)*2/5, widthcancelbind, heightcancelbind)];
        subview.backgroundColor = [UIColor whiteColor];
        subview.layer.cornerRadius = 15;
        subview.userInteractionEnabled = YES;
        [self addSubview:subview];
        
        self.Paycancelbtn =[[UIButton alloc]init];
        [self.Paycancelbtn setImage:[UIImage imageNamed:@"chaDark"] forState:UIControlStateNormal];
        [subview addSubview:self.Paycancelbtn];
        [self.Paycancelbtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(20);
            make.left.mas_offset(20);
            make.size.mas_equalTo(CGSizeMake(20, 20));  //170 65
        }];
        
        UILabel * _leftToplab = [[UILabel alloc]init];
        _leftToplab.text = @"请输入支付密码";
        _leftToplab.textColor = [UIColor blackColor];
        _leftToplab.font = [UIFont systemFontOfSize:15];
        _leftToplab.textAlignment = NSTextAlignmentCenter;
        [subview addSubview:_leftToplab];
        [_leftToplab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(20);
            make.centerX.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(widthcancelbind,20));
        }];
        
        UIView * defaultSubView = [[UIView alloc]initWithFrame:CGRectMake(0, 60, widthcancelbind, 1)];
        defaultSubView.backgroundColor = RGBA(213, 32, 30, 1);
        [subview addSubview:defaultSubView];
        
        UILabel * exitlabel = [[UILabel alloc]init];
        exitlabel.text = @"提现";
        exitlabel.textColor = RGBA(51, 51, 51, 1);
        exitlabel.numberOfLines = 0;
        exitlabel.font = [UIFont systemFontOfSize:15];
        exitlabel.textAlignment = NSTextAlignmentCenter;
        [subview addSubview:exitlabel];
        [exitlabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(defaultSubView.mas_bottom).offset(21);
            make.left.mas_equalTo(tenfloat*3);
            make.size.mas_equalTo(CGSizeMake(widthcancelbind-tenfloat*6, 15));
        }];
        
        self.bring_money = [[UILabel alloc]init];
        self.bring_money.textColor = [UIColor blackColor];
        self.bring_money.numberOfLines = 0;
        self.bring_money.font = [UIFont systemFontOfSize:35];
        self.bring_money.textAlignment = NSTextAlignmentCenter;
        
        [subview addSubview:self.bring_money];
        [self.bring_money mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(exitlabel.mas_bottom).offset(12);
            make.left.mas_equalTo(tenfloat*2);
            make.size.mas_equalTo(CGSizeMake(widthcancelbind-tenfloat*4, 30));
        }];
        
        self.InputSect_cash = [[UIView alloc]init];
        [subview addSubview:self.InputSect_cash];
        [self.InputSect_cash mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bring_money.mas_bottom).offset(25);
            make.left.mas_equalTo(10);
            make.size.mas_equalTo(CGSizeMake(widthcancelbind-20, (widthcancelbind-20)/6));
        }];
        
        self.UnitFieldInput = [[WLUnitField alloc] initWithInputUnitCount:6];
        self.UnitFieldInput.frame = CGRectMake(0, 0, widthcancelbind/4, widthcancelbind/4);
        self.UnitFieldInput.unitSpace = 12;
        self.UnitFieldInput.unitSpace = 6;
        self.UnitFieldInput.secureTextEntry = NO;
        self.UnitFieldInput.secureTextEntry = YES;
        self.UnitFieldInput.layer.borderWidth = 0.6;
        self.UnitFieldInput.layer.borderColor = [UIColor colorWithRed:(51)/255.0 green:(51)/255.0 blue:(51)/255.0 alpha:(1)].CGColor;
        [self.UnitFieldInput sizeToFit];
        
        self.UnitFieldInput.delegate = self;
        [_UnitFieldInput addTarget:self action:@selector(unitFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
        addCode = 0;
        
        [self.InputSect_cash addSubview:self.UnitFieldInput];
        
        self.Payingexitbtn =[[UIButton alloc]init];
        [self.Payingexitbtn setTitle:@"确定" forState:UIControlStateNormal];
        self.Payingexitbtn.titleLabel.font = [UIFont systemFontOfSize:16];
        self.Payingexitbtn.layer.cornerRadius = 15;
        self.Payingexitbtn.layer.masksToBounds = YES;
        [self.Payingexitbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.Payingexitbtn setBackgroundColor:RGBA(213, 32, 30, 1)];
        [subview addSubview:self.Payingexitbtn];
        [self.Payingexitbtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-tenfloat*2);
            make.centerX.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(widthcancelbind-40, 44));
        }];
        
        
         [self.Paycancelbtn addTarget:self action:@selector(cancelbindingOnclicked) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return self;
}

- (void)unitFieldEditingChanged:(WLUnitField*)sender{
    
    self.PaySecret = sender.text;
    
    if (sender.tag == 5) {
        
    }
    
}

- (BOOL)unitField:(WLUnitField *)uniField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    // 判断是不是“删除”字符
    if (string.length != 0) {// 不是“删除”字符
        self.codeStr = [uniField.text stringByAppendingString:string];
    } else { // 是“删除”字符
        self.codeStr = [uniField.text substringToIndex:uniField.text.length - 1];
    }
    
    addCode++;
    
    if (addCode == 6) {
        
//        CashHandSecondTBV * loginuser = [[CashHandSecondTBV alloc]init];
//        [self.navigationController pushViewController:loginuser animated:YES];
        
    }
    
    return YES;
}

- (void)cancelbindingOnclicked{
    [self removeFromSuperview];
}


@end
